//导入vue-router
import {createRouter,createWebHistory} from "vue-router";
//导入组件
import showCategory from "@/views/catalog/showCategory.vue";
import showProduct from  "@/views/catalog/showProduct.vue"
import showItem from "@/views/catalog/showItem.vue"
import loginForm from "@/views/user/LoginForm.vue"
import myAccount from "@/views/user/myAccount.vue"
// import chatForm from "@/views/user/chatForm.vue"
// import giteeForm from "@/components/giteeTest/giteeForm.vue"
import giteeLogin from "@/components/giteeTest/giteeLogin.vue"
import giteeRegister from "@/components/giteeTest/giteeRegister.vue"
import mainForm from "@/views/catalog/mainForm.vue";
import showCart from "@/views/cartOrder/showCart.vue"
import confirmOrder from "@/views/cartOrder/confirmOrder.vue"
import userOrders from "@/views/user/userOrders.vue"
import payForm from"@/views/cartOrder/payForm.vue"
import orderDetails from "@/views/user/orderDetails.vue"
import helpText from "@/components/helpText.vue"
import searchResult from "@/views/catalog/showSearchResult.vue"

// import giteeVue from "@/components/giteeTest/giteeVue.vue"
// import giteeLogin from "@/components/giteeTest/giteeLogin.vue"
// import giteeRegister from "@/components/giteeTest/giteeRegister.vue"

//定义路由关系

const routes=[
    {path: '/categoryForm' ,component:showCategory},
    {path: '/productForm' ,component: showProduct},
    {path: '/itemForm',component: showItem},
    {path: '/login',component: loginForm},
    {path: '/itemForm',component: showItem},
    // {path: '/testGitee',component: giteeForm},
    {path: '/giteeLogin',component: giteeLogin},
    {path: '/giteeRegister',component: giteeRegister},
    {path: '/myAccountFrom',component: myAccount},
    // {path: '/chatForm', component: chatForm},
    {path: '/main',component: mainForm},
    {path:'/',component: mainForm},
    {path:'/cartForm',component: showCart,
     beforeEnter:(to,from,next)=>{
        const login= localStorage.getItem("token");
        if(login){
            next();
        }else{
            setTimeout(()=>{
                alert('请先登录再查看购物车')
                next('/login')
            },0)
        }
     }},
    {path:'/userOrders',component: userOrders},
    {path: '/confirmOrder',component: confirmOrder},
    {path:'/payForm',component: payForm},
    {path:'/orderDetails',component: orderDetails},
    {path:'/helpText',component: helpText},
    {path:'/searchResult',component:searchResult }

]

//创建路由
const router=createRouter({
    history:createWebHistory(),
    routes:routes
})

export default router